package com.tbit.uqbike.service.business.impl;


import com.github.pagehelper.PageHelper;
import com.tbit.uqbike.object.pojo.BikeModel;
import com.tbit.uqbike.service.business.BikeModelService;
import com.tbit.uqbike.webmanager.dao.data.BikeModelDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆型号表(BikeModel)表服务实现类
 *
 * @author jing
 * @since 2020-12-04 10:14:30
 */
@Service("bikeModelService")
public class BikeModelServiceImpl implements BikeModelService {
    @Resource
    private BikeModelDao bikeModelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param bikeModelId 主键
     * @return 实例对象
     */
    @Override
    public BikeModel queryById(Integer bikeModelId) {
        return this.bikeModelDao.queryById(bikeModelId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BikeModel> queryAllByLimit(int offset, int limit) {
        return this.bikeModelDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bikeModel 实例对象
     * @return 实例对象
     */
    @Override
    public BikeModel insert(BikeModel bikeModel) {
        this.bikeModelDao.insert(bikeModel);
        return bikeModel;
    }

    /**
     * 修改数据
     *
     * @param bikeModel 实例对象
     * @return 实例对象
     */
    @Override
    public BikeModel update(BikeModel bikeModel) {
        this.bikeModelDao.update(bikeModel);
        return this.queryById(bikeModel.getBikeModelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param bikeModelId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer bikeModelId) {
        return this.bikeModelDao.deleteById(bikeModelId) > 0;
    }

    @Override
    public List<BikeModel> queryPage(BikeModel bikeModel) {
        PageHelper.startPage(bikeModel.getPage().getPageNO(), bikeModel.getPage().getRowCount());
        return bikeModelDao.queryAll(bikeModel);
    }
}